package com.panshi.modules.common.answer;

import com.panshi.AnswerApi;
import com.panshi.api.util.CommonResult;
import com.panshi.api.util.PageSizeVO;
import com.panshi.bean.AnswerNoBean;
import com.panshi.bean.IssBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.Date;
import java.util.List;

/**
 * @author :jiege
 * @description :
 * @create :2020-08-18 19:06:00
 */

@Controller
@Api(tags = "回答未审核接口")
public class UnAnswerController {

    @Autowired
    private AnswerApi answerApi;

    @GetMapping("/answer/unlist")
    @ApiOperation(value = "未审核回答页面")
    @RequiresPermissions("unanswer:list")
    public ModelAndView unanswerpage(){
        return new ModelAndView("/answer/unanswer-list");
    }

    @GetMapping("/answer/listno")
    @ResponseBody
    @RequiresPermissions("unanswer:list")
    @ApiOperation(value = "未审核回答数据")
    public PageSizeVO<List<AnswerNoBean>> queryunanswerlist(Integer currentPage, Integer pageSize, String state){
        System.out.println(currentPage+"============"+pageSize);
        PageSizeVO<String> pageSizeBean = new PageSizeVO<>();
        pageSizeBean.setStartIndex(currentPage);
        pageSizeBean.setPageSize(pageSize);
        pageSizeBean.setState(state);
        return  answerApi.adminFindAnswerNo(pageSizeBean);
    }


    @PostMapping("/answer/updateno")
    @ResponseBody
    @RequiresPermissions("unanswer:update")
    @ApiOperation(value = "未审核回答状态")
    public CommonResult<String> updateanswerlist(AnswerNoBean issBean) throws Exception {
        issBean.setCreated_time(new Date());
        if(issBean.getState()==2){
            answerApi.adminAnswerNo(issBean);
        }else if(issBean.getState()==3){
            answerApi.adminInitAnswer(issBean);
        }
        return new CommonResult<>();
    }

}
